package com.informationsystem.service.impl;

import com.informationsystem.dao.NoticeDao;
import com.informationsystem.model.News;
import com.informationsystem.model.Notice;
import com.informationsystem.service.NoticeManager;
import com.informationsystem.service.impl.GenericManagerImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.jws.WebService;

@Service("noticeManager")
@WebService(serviceName = "NoticeService", endpointInterface = "com.informationsystem.service.NoticeManager")
public class NoticeManagerImpl extends GenericManagerImpl<Notice, Long> implements NoticeManager {
    NoticeDao noticeDao;

    @Autowired
    public NoticeManagerImpl(NoticeDao noticeDao) {
        super(noticeDao);
        this.noticeDao = noticeDao;
    }

	@Override
	public List getNoticeList() {
		List<Notice> noticeList = getAll();
		Collections.sort(noticeList, new PostDateDsc());
		return noticeList;
	}
	
	private  class PostDateDsc implements  Comparator<Notice>{
		@Override
		public int compare(Notice o1, Notice o2) {
			return o2.getPostDate().compareTo(o1.getPostDate());
		}
	}

	@Override
	public List getTop12NoticeList() {
		List noticeList = getNoticeList();
		if(noticeList.size()>12)
		noticeList = noticeList.subList(0, 11);
		return noticeList;
	}
}